<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.laputa.service.model.MainFrameData"%>
<%@ page import="com.laputa.model.City"%>
<%@ page import="com.laputa.model.Ground"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
	<%
		MainFrameData data = (MainFrameData) pageContext.findAttribute("userData");
		MainFrameData friendData = (MainFrameData) pageContext.findAttribute("friendData");
		
		request.setAttribute("userName", data.getName());
		
		City city = data.getCity();
		String thisName = data.getName();
		if (friendData != null) {
			thisName = friendData.getName();
			city = friendData.getCity();
		}
	 %>

<head>
	<base href="<%=basePath%>">
	<title>地产大亨：${userName}的主页面</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<link rel="stylesheet" type="text/css" href="css/main.css">
</head>

<body background="pic/background.jpg">

<table id="banner" width="100%">
    <tr>
		<td align="center">
			<font size="30" color="blue"> 欢迎，用户${userName}</font>
		</td>
    </tr>

</table>

<table>
	<tr>
		<table align=right valign="bottom">
		    <tr>
				<td align="right">
					<form name="myForm" method="post" action="friendList.do">
						<input type="submit" name="showList" value="好友列表">
					</form>
					<form method="post" action="login.do">
						<input type="submit" name="home" value="返回" />
					</form>
					<form method="post" action="login.do">
						<input type="submit" name="logout" value="登出"/>
					</form>
				</td>
			</tr>
		</table>
		
		<%
			Set<Long> grounds = city.getGroundID();
			Iterator<Long> iterator = grounds.iterator();
			int p = 0;
			while (iterator.hasNext())
			{
				Long l = iterator.next();
				Ground ground = city.getGround(l);
				p++;
				if (p % 4 == 0)
				{
					out.print("<table>");
					out.print("<tr>");
					out.print("<td align=\"left\">");
					out.print("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\">");
					if (ground.getBuilding() == null)
						out.print("<img name=\"ground" + p + "\" src=\"buildings/ground.png\" width=\"170\" height=\"240\" hspace=\"50\">");    
					else
						out.print("<img name=\"ground" + p + "\" src=\"buildings/building"+ ground.getBuilding().getType() + ".png\" width=\"170\" height=\"240\" hspace=\"50\">");    
					out.print("<tr>");
					out.print("<form method =\"post\" action=\"showGround.do\">");
					out.print("<input type = \"hidden\" name = \"groundID\" value =" + l +">");
					out.print("<td align=\"center\"> <input type = \"submit\" name = \"show\" value = \"显示土地信息\"></td>");
					out.print("</form>");
					out.print("</tr>");
					out.print("</table>");
					out.print("</td>");
					out.print("</tr>");
					out.print("</table>");
				}
				else
				{
					out.print("<table align=\"left\" valign=\"top\">");
					out.print("<tr>");
					out.print("<td align=\"left\">");
					out.print("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\">");
					if (ground.getBuilding() == null)
						out.print("<img name=\"ground" + p + "\" src=\"buildings/ground.png\" width=\"170\" height=\"240\" hspace=\"50\">");    
					else
						out.print("<img name=\"ground" + p + "\" src=\"buildings/building"+ ground.getBuilding().getType() + ".png\" width=\"170\" height=\"240\" hspace=\"50\">");    
					out.print("<tr>");
					out.print("<form method=\"post\" action=\"showGround.do\">");
					out.print("<input type=\"hidden\" name=\"groundID\" value=" + l +">");
					out.print("<td align=\"center\"> <input type = \"submit\" name = \"show\" value = \"显示土地信息\"></td>");
					out.print("</form>");
					out.print("</tr>");
					out.print("</table>");
					out.print("</td>");
					out.print("</tr>");
					out.print("</table>");
				}
			}
		%>
	</tr>
</table>

</body>
</html>
